home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 24 / CU Amiga Magazine's Super CD-ROM 24 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-07].iso / CUCD / Programming / SWI / source / boot / foreign.pl < prev    next >
Encoding:
Text File  |  1995-08-16  |  2.6 KB  |  113 lines

  1. /*  $Id: foreign.pl,v 1.4 1995/08/16 11:49:19 jan Exp $
  2.  
  3.     Copyright (c) 1990 Jan Wielemaker. All rights reserved.
  4.     jan@swi.psy.uva.nl
  5.  
  6.     Purpose: Foreign language loader front end
  7. */
  8.  
  9. :- module($foreign,
  10.     [ load_foreign/5
  11.     , load_foreign/2
  12.     , foreign_file/1
  13.     ]).
  14.  
  15. :- module_transparent
  16.     load_foreign/5,
  17.     load_foreign_/5,
  18.     load_foreign/2.
  19.  
  20. %    foreign_file(?File)
  21. %    Is true if 'File' is loaded as a foreign file.
  22.  
  23. foreign_file(File) :-
  24.     recorded($foreign_file, File).
  25.  
  26. %    load_foreign(+File, +Entry)
  27. %    Load foreign file and initialise with specified entry.
  28.  
  29. load_foreign(File, Entry) :-
  30.     load_foreign(File, Entry, '', '', 0).
  31.  
  32. %    load_foreign(+File, +Entry, +Options, +Libraries, +Size)
  33. %    Load a (list of) .o file(s) as produced with  'cc  -c  ...'  and
  34. %    install the foreign predicates defined in them. 
  35.  
  36. load_foreign(Files, Entry, Options, Libraries, Size) :-
  37.     statistics(heapused, OldHeap),
  38.     statistics(cputime, OldTime),
  39.  
  40.     (   load_foreign_(Files, Entry, Options, Libraries, Size)
  41.     ;   true
  42.     ), !,
  43.  
  44.     statistics(heapused, Heap),
  45.     statistics(cputime, Time),
  46.     HeapUsed is Heap - OldHeap,
  47.     TimeUsed is Time - OldTime,
  48.  
  49.     confirm_files(Files, CFs),
  50.     list_to_atom(CFs, CF),
  51.     context_module(M),
  52.     module_spec(M, ModSpec),
  53.     $ttyformat('Foreign file(s) ~w loaded~w, ~2f seconds, ~D bytes~n',
  54.                     [CF, ModSpec, TimeUsed, HeapUsed]).
  55.     
  56. module_spec(user, '') :- !.
  57. module_spec(M, S) :-
  58.     sformat(S, ' into ~w', [M]).
  59.  
  60. confirm_files([], []) :- !.
  61. confirm_files([H|T], [CH|CT]) :- !,
  62.     confirm_file(H, CH),
  63.     confirm_files(T, CT).
  64. confirm_files(F, CF) :-
  65.     confirm_file(F, CF).
  66.  
  67. confirm_file(library(File), Confirm) :- !,
  68.     check_files(library(File), Confirm).
  69. confirm_file(File, File).
  70.  
  71. load_foreign_(Files, Entry, Options, Libraries, Size) :-
  72.     check_files(Files, Expanded),
  73.     list_to_atom(Expanded, F),    
  74.     list_to_atom(Options, O),
  75.     list_to_atom(Libraries, L),
  76.  
  77.     $load_foreign(F, Entry, O, L, Size),
  78.     record_foreigns(Expanded).
  79.  
  80. check_files(0, _) :- !, fail.        /* variable file name */
  81. check_files([], []) :- !.
  82. check_files([F|R], [A|T]) :- !,
  83.     check_files(F, A),
  84.     check_files(R, T).
  85. check_files(F, A) :-
  86.     absolute_file_name(F,
  87.                [ extensions(['.o', '.a', '']),
  88.                  access(read)
  89.                ], A), !.
  90. check_files(F, _) :-
  91.     $warning('~w: No such foreign file', [F]),
  92.     fail.
  93.  
  94. list_to_atom(Atom, Atom) :-
  95.     atomic(Atom), !.    
  96. list_to_atom(List, Atom) :-
  97.     insert_spaces(List, SPList),    
  98.     concat_atom(SPList, Atom).
  99.  
  100. insert_spaces([One], [One]) :- !.
  101. insert_spaces([H|T], [H, ' '| R]) :-
  102.     insert_spaces(T, R).
  103.  
  104. record_foreigns([]) :- !.
  105. record_foreigns([H|T]) :- !,
  106.     record_foreigns(H),
  107.     record_foreigns(T).
  108. record_foreigns(F) :-
  109.     absolute_file_name(F, Path),
  110.     (   recorded($foreign_file, Path)
  111.     ;   recordz($foreign_file, F)
  112.     ), !.
  113.